PRA9: Shelby Goes Shopping! // Advanced

 
Mr. Shelby recently journeyed to Whole Foods in order to purchase eggplant, but when he was in line he saw a special promotion, namely a "Buy two, get two for free" offer. The two items he buys can be of varying price, but Whole Foods always charges for the 2 most costly items and gives other 2 as free. For example, if the items cost 9, 11, 22, 52, then you have to pay 74 and take all 4 items.

Mr. Shelby is busy reordering his items to reduce the total price he has to pay. He can separate the items and get them on different bills if needed. What is the least price Shelby has to pay to buy all the N items?

Input Format

First line of each test case has a single integer N, the number of items Mr. Shelby wants to buy. The second line of each test case has N space separated integers, which are the costs of items Mr. Shelby wants to buy.

Sample Input

SAMPLE INPUT #1
4
1 1 2 2

SAMPLE INPUT #2
2
10 200

SAMPLE INPUT #3
7
1 1 10 2 2 2 1

Output Format

The least price Mr. Shelby has to pay.

Sample Output

SAMPLE OUTPUT #1
4

SAMPLE OUTPUT #2
210

SAMPLE OUTPUT #3
14




You must be logged in to submit a solution.